package org.microdream.easy.deploy.action;

import ice.server.comm.BaseAction;
import ice.server.comm.BaseOperateResult;
import ice.server.comm.ParamBulider;
import org.microdream.easy.deploy.po.DApp;
import org.microdream.easy.deploy.service.DAppService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Title: app controller
 * @author:沈明可
 * @create: 2019-09-09 21:11
 */
@RestController
@RequestMapping("App")
public class AppAction extends BaseAction {

    @Resource
    private DAppService dAppService;

    /**
     * 功能描述:〈app信息分页展示〉
     *
     * @param limit       页面大小
     * @param offset      当前页码
     * @param projectCode 项目编码
     * @param appCode     app编码 支持模糊查询
     * @param appName     app名称 支持模糊查询
     * @return : java.util.Map
     * @author : 沈明可
     * @date : 2019/9/10 10:23
     * User :
     */
    @PostMapping("/searchByPage")
    public Map searchByPage(Integer limit, Integer offset, String projectCode, String appCode, String appName) {
        if (limit == null || offset == null) {
            return null;
        }
        return dAppService.searchByPage(ParamBulider.build()
                .addPageAndRow(offset / limit, limit)
                .add("projectCode", projectCode)
                .add("appCode_cons", appCode)
                .add("appName_cons", appName).get()
        );
    }

    /**
     * 功能描述:〈app新增〉
     *
     * @param app 实体类
     * @return : ice.server.comm.BaseOperateResult
     * @author : 沈明可
     * @date : 2019/9/10 10:26
     * User :
     */
    @PostMapping("/add")
    public BaseOperateResult add(DApp app) {
        return dAppService.add(app);
    }

    /**
     * 功能描述:〈app修改〉
     *
     * @param app 实体类
     * @return : ice.server.comm.BaseOperateResult
     * @author : 沈明可
     * @date : 2019/9/10 10:26
     * User :
     */
    @PutMapping("/update")
    public BaseOperateResult update(DApp app) {
        return dAppService.update(app);
    }

    /**
     * 功能描述:〈app删除〉
     *
     * @param ids appId
     * @return : ice.server.comm.BaseOperateResult
     * @author : 沈明可
     * @date : 2019/9/15 20:55
     * User :
     */
    @DeleteMapping("/delete")
    public BaseOperateResult delete(String ids) {
        return dAppService.delete(ids);
    }
}
